package operation;

import book.Book;
import book.BookList;

import java.util.Scanner;

public class Add implements IOperation{
    public void work(BookList bookList) {
        System.out.println("==新增图书==");

        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入图书名字:>");
        String name = scanner.nextLine();
        System.out.println("请输入作者姓名:>");
        String author = scanner.nextLine();
        System.out.println("请输入图书价格:>");
        int price= scanner.nextInt();
        scanner.nextLine();//接收上一步留下的回车键
        System.out.println("请输入图书类型:>");
        String type = scanner.nextLine();

        //创建一个Book类型的对象存储这本书
        Book book = new Book(name,author,price,type);
        //把书放进书架(这里相当于尾插)
        int currentUserSize = bookList.getUsedSize();
        bookList.setPosBooks(currentUserSize,book);
        bookList.setUsedSize(currentUserSize+1);
        System.out.println("增添成功！");
    }
}
